package com.itheima.put;

import java.io.*;
import java.util.Arrays;

public class Test7 {
    public static void main(String[] args) throws IOException {
//        复制一个文件夹到另一个文件夹中，复制内容包括文件夹中的内容
        //method1();
        //method2(f1);
        // File f1=new File("D:\\E盘\\game\\三国群英传7");
        File f1 = new File("D:\\新建文件夹");
        method2(f1, "D:\\NewVideo");
    }

    private static void method2(File f1, String s) throws IOException {
        if (!f1.exists() && f1 == null) {
            return;
        }
        for (File file : f1.listFiles()) {
            if (file.isFile()) {
                //复制文件
                method1(file,s);
            } else {
                File file1 = new File(s, file.getName());
                file1.mkdirs();
                method2(file, file1.toString());
            }
        }
        File newFile = new File(s, f1.getName());
        newFile.mkdirs();

    }

    private static void method1(File listFile,String s) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(listFile));
        File file = new File(s, listFile.getName());
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
        int b;
        byte[] bytes = new byte[1024];
        while ((b = bis.read(bytes)) != -1) {
            bos.write(bytes);
        }
        bos.close();
        bis.close();
    }
}
